package com.lely.service.impl;

import com.lely.dao.RoleDao;
import com.lely.entity.Role;
import com.lely.service.RoleService;
import java.util.List;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author lely
 * @date 2021/4/15 13:46
 */
@Service
public class RoleServiceImpl  implements RoleService {

    @Autowired
    public RoleDao roleDao;

    @Override
    public Role get(Long id) {
        return roleDao.get(id);
    }

    @Override
    public List<Role> getAll(Map condition) {
        return roleDao.getAll(condition);
    }

    @Override
    public Integer count(String rolename){
        return roleDao.count(rolename);
    }

    @Override
    public Integer add(Role role) {
        return roleDao.add(role);
    }

    @Override
    public int update(Role role) {
        return roleDao.update(role);
    }

    @Override
    public int delete(Long id) {
        //查询是否存在关联的用户
        Role role = roleDao.get(id);
        Integer count = roleDao.countByUserId(role.getRoleId());
        if(count>0){
            return -1;
        }
        return roleDao.delete(id);
    }
}
